#!/usr/bin/env bash
# Written in [Amber](https://amber-lang.com/)
# version: 0.4.0-alpha
# date: 2025-02-17 19:19:12
dir_exists__32_v0() {

# bshchk (https://git.blek.codes/blek/bshchk)
deps=('[' '[' 'return' 'return' '[' 'bc' 'sed' 'mkdir' '[' '[' 'return' 'return' '[' 'curl' '[' 'wget' '[' 'aria2c' 'return' 'return' 'basename' '[' 'break' 'gzip' '[' 'break')
non_ok=()

for d in $deps
do
    if ! command -v $d > /dev/null 2>&1; then
        non_ok+=$d
    fi
done

if (( ${#non_ok[@]} != 0 )); then
    >&2 echo "RDC Failed!"
    >&2 echo "  This program requires these commands:"
    >&2 echo "  > $deps"
    >&2 echo "    --- "
    >&2 echo "  From which, these are missing:"
    >&2 echo "  > $non_ok"
    >&2 echo "Make sure that those are installed and are present in \$PATH."
    exit 1
fi

unset non_ok
unset deps
# Dependencies are OK at this point


    local path=$1
    [ -d "${path}" ]
    __AS=$?
    if [ $__AS != 0 ]; then
        __AF_dir_exists32_v0=0
        return 0
    fi
    __AF_dir_exists32_v0=1
    return 0
}
dir_create__38_v0() {
    local path=$1
    dir_exists__32_v0 "${path}"
    __AF_dir_exists32_v0__52_12="$__AF_dir_exists32_v0"
    if [ $(echo '!' "$__AF_dir_exists32_v0__52_12" | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then
        mkdir -p "${path}"
        __AS=$?
    fi
}
is_command__93_v0() {
    local command=$1
    [ -x "$(command -v ${command})" ]
    __AS=$?
    if [ $__AS != 0 ]; then
        __AF_is_command93_v0=0
        return 0
    fi
    __AF_is_command93_v0=1
    return 0
}
file_download__135_v0() {
    local url=$1
    local path=$2
    is_command__93_v0 "curl"
    __AF_is_command93_v0__9_9="$__AF_is_command93_v0"
    is_command__93_v0 "wget"
    __AF_is_command93_v0__12_9="$__AF_is_command93_v0"
    is_command__93_v0 "aria2c"
    __AF_is_command93_v0__15_9="$__AF_is_command93_v0"
    if [ "$__AF_is_command93_v0__9_9" != 0 ]; then
        curl -L -o "${path}" "${url}"
        __AS=$?
    elif [ "$__AF_is_command93_v0__12_9" != 0 ]; then
        wget "${url}" -P "${path}"
        __AS=$?
    elif [ "$__AF_is_command93_v0__15_9" != 0 ]; then
        aria2c "${url}" -d "${path}"
        __AS=$?
    else
        __AF_file_download135_v0=0
        return 0
    fi
    __AF_file_download135_v0=1
    return 0
}
dir_create__38_v0 "data"
__AF_dir_create38_v0__4_1="$__AF_dir_create38_v0"
echo "$__AF_dir_create38_v0__4_1" >/dev/null 2>&1
while IFS= read -r line; do
    __AMBER_VAL_0=$(basename ${line})
    __AS=$?
    if [ $__AS != 0 ]; then
        echo "Failed to get file name"
        break
    fi
    file_name="${__AMBER_VAL_0}"
    echo "Downloading: ""${file_name}"
    file_download__135_v0 "${line}" "data/""${file_name}"
    __AF_file_download135_v0__11_5="$__AF_file_download135_v0"
    echo "$__AF_file_download135_v0__11_5" >/dev/null 2>&1
    echo "Unzipping: ""data/""${file_name}"
    gzip -d data/${file_name}
    __AS=$?
    if [ $__AS != 0 ]; then
        echo "Failed to unzip file"
        break
    fi
done <"data_urls.txt"
